﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using Recon.Portal.Business;
using Recon.Portal.DataObjects;

namespace Recon.Portal.WebUI
{
    public partial class SearchRemitter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                control.Value = Request.QueryString["textbox"].ToString();
                path.Value = Request.QueryString["PageRequest"].ToString();
                BindGrid();
                txtRemitterId.Focus();

            }
        }

        #region User Defined Function

        public void BindGrid()
        {
            RemitterEntity remitEntity = new RemitterEntity();
            List<Remitter> remitterLst = null;
            try
            {

                if (txtRemitterId.Text.Trim() == "")
                {
                    remitterLst = remitEntity.GetRemitterDetails(Convert.ToString(control.Value).Trim(), ((User)Session["CurrentUserVO"]).CustomerID);
                }
                else
                {
                    remitterLst = remitEntity.GetRemitterDetails(Convert.ToString(txtRemitterId.Text).Trim(), ((User)Session["CurrentUserVO"]).CustomerID);
                }

                   // if (remit == null)
                if(remitterLst == null || remitterLst.Count <=0)
                {
                    lblRemittercnt.Text = "No Records Found";
                }
                else
                {
                    //List<Remitter> remitList = new List<Remitter>();
                    // remitList.Add(remit);
                    gvRemitter.DataSource = remitterLst;
                    gvRemitter.DataBind();
                    lblRemittercnt.Text = ((List<Remitter>)gvRemitter.DataSource).Count.ToString() + " records found.";
                }
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
        //protected void gvRemitter_PageIndexChanging(object sender, GridViewPageEventArgs e)
        //{
        //    gvRemitter.PageIndex = e.NewPageIndex;
        //    BindGrid();
        //}

        protected void gvRemitter_SelectedIndexChanged(object sender, EventArgs e)
        {
            string remitterid;
            remitterid = ((LinkButton)gvRemitter.SelectedRow.FindControl("lbtnRemitterid")).Text;
            string strScript = "<script>";
            strScript += "window.opener.document.all('ctl00$BodyHolder$txtRemitterId').value = '" + remitterid + "';";
            strScript += "self.close();</script>";
            Response.Write(strScript);
        }

        protected void gvRemitter_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            gvRemitter.PageIndex = 0;
            gvRemitter.DataSource = null;
            gvRemitter.DataBind();
            BindGrid();
        }
    }
}